package study.ai.deepseek4j.controller;

import io.github.pigmesh.ai.deepseek.config.DeepSeekProperties;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionRequest;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import io.github.pigmesh.ai.deepseek.core.chat.ResponseFormatType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@Slf4j
@RestController
public class ChatController {

    @Autowired
    private DeepSeekClient deepSeekClient;

    @Autowired
    private DeepSeekProperties deepSeekProperties;

    /**
     * 流
     */
    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chat(String prompt) {
        return deepSeekClient.chatFluxCompletion(prompt);
    }


    @GetMapping(value = "/sync/advanced")
    public ChatCompletionResponse chatAdvanced(String prompt) {
        ChatCompletionRequest request = ChatCompletionRequest.builder()
                // 根据渠道模型名称动态修改这个参数
                .model(deepSeekProperties.getModel())
                .addUserMessage(prompt)
                .responseFormat(ResponseFormatType.TEXT)
                .tools()
                .build();

        return deepSeekClient.chatCompletion(request).execute();
    }

    @GetMapping(value = "/sync/chat")
    public ChatCompletionResponse syncChat(String prompt) {
        ChatCompletionRequest request = ChatCompletionRequest.builder()
                // 根据渠道模型名称动态修改这个参数
//                .model(deepSeekProperties.getModel())
                .addUserMessage(prompt)
                .build();

        return deepSeekClient.chatCompletion(request).execute();
    }
}
